PREPROCESSING : file inclusion, macros, conditional inclusion, pragmas
_________________________________________________________________________

FILE INCLUSION

You use the '#include' preprocessing directive to include header files.  The entire contents of the specified file is inserted in place of the file inclusion statement.  The following are some examples:

  #include <iostream.h>
  #include <stdlib.h>
  #include "myHeader.h"

The '<>' brackets identify standard libraries which are part of the compiler and follow implementation-defined rules to find the file.  The double-quote brackets define local files (usually within the directory or sub-directories that your project file is located in).

MACROS

Macros use the '#define' preprocessing directive to substitute any occurrence of the macro 'name' with the identified text in the macro definition.  Examples include:

  #define MAX_CHARS 255
  #define ERROR_STR "\pError, try again."
  #define MAX(A,B)  ( (A)>(B) ? (A) : (B) )

CONDITIONAL INCLUSION

You can use conditional inclusion preprocessing directives to define or include items which are compiler or operating system specific.

  #ifndef OS
  #define OS MAC
  #endif

  #if OS == MAC
    #define SYS_HEADER "MacOS.h"
  #elif OS == WIN
    #define SYS_HEADER "Win.h"
  #elif OS = WIN95
    #define SYS_HEADER "Win95.h"
  #elif OS = UNIX
    #define SYS_HEADER "Unix.h"
  #endif
  #include SYS_HEADER

PRAGMA DIRECTIVES

Pragma directives are compiler-specific and therefore, tend to be less portable.  The format for THINK C pragma directives is:

  #pragma [SC] pragma_directive [pragma_args]

If you specify SC, the directive must be recognized by Symantec C/C++ compilers.  Some examples of THINK C pragma directives include:

  #pragma [SC] align [1/2/4]         // sets byte alignments within
                                     // structures.

  #pragma [SC] message "text"        // prints text while compiling.

  #pragma [SC] once                  // when included in a header file,
                                     // file is included only once even
                                     // if #include directives include
                                     // it multiple times.

  #pragma [SC] options align=power   // equivalent to align 4 directive.
  #pragma [SC] options align=native

  #pragma [SC] options align=mac68k  // equivalent to align 2 directive.

  #pragma [SC] options align=reset   // default alignment.

  #pragma [SC] template class<args>  // produces instantiations of a
                                     // template.

  #pragma [SC] template_access code  // code type can be public, extern,
                                     // or static.